package com.lxh.lxhcrm.controller.aftersale;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.lxh.lxhcrm.model.pojos.Knowledge;
import com.lxh.lxhcrm.model.pojos.KnowledgeClassify;
import com.lxh.lxhcrm.model.service.AfterSaleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;


import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 开发团队 ：lxh
 * 开发人员 ：李兴洋
 * 开发时间 ：2020年1月9日18:57:37
 * 类的名称 ：KnowLedgeController
 * 类的描述 ：售后模块中的知识库
 */
@RestController
@RequestMapping("/after-sale/knowledge")
public class KnowLedgeController {
    @Autowired
    AfterSaleService afterSaleService;

    //所有文章
    @RequestMapping("/knowledge-list")
    public Map<String,Object> knowledgesList(Integer page , Integer size , String search , String kcName , String orderByChose){
        Page<Object> obj = PageHelper.startPage(page, size);
        List<Knowledge> kList = afterSaleService.findAllKnowledge(search,kcName,orderByChose);

        Map<String,Object> kMap = new HashMap<>();
        kMap.put("total",obj.getTotal());
        kMap.put("rows",kList);
        return kMap;
    }

    @RequestMapping("/knowledgeClassify-list")
    public List<KnowledgeClassify> knowledgeClassifyList(){
        return afterSaleService.findAllKnowledgeClassify();
    }

    @RequestMapping("/add-knowledge")
    @ResponseBody
    public void addKnowledge(@RequestBody Knowledge knowledge){
        //System.out.print(knowledge.getEmp());
        afterSaleService.addKnowledge(knowledge);
    }

    //审批
    @RequestMapping("/knowledgeCheck")
    @ResponseBody
    public void knowledgeCheck(Integer essId){
        afterSaleService.knowledgeCheck(essId);
    }

    //删除知识库
    @RequestMapping("/delete-k")
    @ResponseBody
    public void deleteK(Integer kNo){
        afterSaleService.deleteK(kNo);
    }

    //新增知识库分类
    @RequestMapping("/add-knowledgeClassify")
    @ResponseBody
    public void addKnowledgeClassify (KnowledgeClassify kc){
        afterSaleService.addKnowledgeClassify(kc);
    }

    //删除知识库分类
    @RequestMapping("/delete-kc")
    @ResponseBody
    public void deleteKc(Integer kcNo){
        afterSaleService.deleteKc(kcNo);
    }
}
